$(function()
{
	var topNavbarVue = new Vue({
				el : '#adminTopNavbar',
				data:function(){ 
					var $this=this;
					var validatePass2=function(rule, value, callback) {  //确认新密码
			        	if (value !== $this.form.newPwd) {
				          callback(new Error('两次输入密码不一致!'));
				        } else {
				          callback();
				        }
			        };
			        var checkPwd=function(rule, value, callback){ //验证当前密码
			        	var url=ctx+"/admin/user/checkPwd";
			        	$.ajax({url:url,type:"POST",dataType:"json",data:{pwd:value},success:function(data){
			        		if(data.data.success==true)
			        		{
			        			callback();
			        		}
			        		else
			        		{
			        			callback(new Error('登录密码不正确!'));
			        		}
			        	}});
			        };
					return{
					   dialogUpdatePwdVisible:false,
					   form: {
				          oldPwd:"",
				          newPwd:"",
				          confirmNewPwd:""
				        },
				        pwdRules:{
				        	oldPwd:[
				        		{ required: true, message: '登录密码不能为空', trigger: 'blur' },
				        		{ validator:checkPwd, trigger: 'blur' }
				        	],
				        	newPwd:[{ required: true, message: '新密码不能为空', trigger: 'blur' }],
				        	confirmNewPwd:[
				        		{ required: true, message: '确认新密码不能为空', trigger: 'blur' },
				        	    { validator:validatePass2, trigger: 'blur' }
				        	]
				        }
					};
				},
				methods:{
					closePwdDialog:function(event){ //关闭修改密码窗口
						this.$refs["updatePwdForm"].resetFields();
					},
					updatePwd:function(event) //保存密码
					{
						var $this=this;
						this.$refs["updatePwdForm"].validate(function(valid){
							if(valid)
							{
								var url=ctx+"/admin/user//update/pwd";
								$.ajax({url:url,type:"POST",dataType:"json",data:$this.form,success:function(data){
					        		if(data.data.success==true)
				        			{
					        			$this.$message({
				        		          showClose: true,
				        		          message: '修改密码成功！',
				        		          type: 'success'
				        		        });
					        			$this.dialogUpdatePwdVisible=false;
				        			}
					        		else
					        		{
					        			$this.$message({
					        		          showClose: true,
					        		          message: data.data.msg,
					        		          type: 'error'
					        		        });
					        		}
					        	}});
							}
							else 
							{
							   return false;
							}
						});
					}
				}
			});
});